<template>
  <div class="container">
    <div class="top_box">
      <el-carousel>
        <el-carousel-item>
          <el-image :src="bgimg" fit="fill"></el-image>
        </el-carousel-item>
      </el-carousel>
    </div>

    <div class="list_wraper">
      <div class="pro_intro">{{ homeIntroduce }}</div>
      <h3>植物展示</h3>
      <ConItem :plantMaterialList="plantMaterialList" />
      <div class="divide">
        <el-divider content-position="right"
          ><span @click="goPlantList">查看更多</span></el-divider
        >
      </div>

      <h3>热门案例</h3>
      <el-row>
        <el-col
          :xs="24"
          :sm="24"
          :lg="8"
          v-for="(item, index) in baseCaseList"
          :key="index"
          style="padding: 5px 10px"
        >
          <div class="case_wraper">
            <div style="height: 250px">
              <el-image
                style="width: 100%; height: 100%"
                :src="imgUrl + item.img"
              />
            </div>
            <div class="item_title">{{ item.name }}</div>
            <div class="item_desc">{{ item.description }}</div>
          </div>
        </el-col>
      </el-row>
      <div class="divide">
        <el-divider content-position="right"
          ><span @click="goCaseLsit">查看更多</span></el-divider
        >
      </div>
    </div>
  </div>
</template>

<script>
// import bgimg from "@/assets/imgs/bg.png";
import bgimg from "@/assets/imgs/08051.jpg";

import ConItem from "./components/ConItem.vue";

import { getHomeInfo } from '@/api/home.js'
export default {
  name: "MainPage",
  components: {
    ConItem
  },
  data() {
    return {
      bgimg,
      carouselImageList: [],
      plantMaterialList: [],
      baseCaseList: [],
      homeIntroduce: ''
    };
  },
  created() {
    this.getHomeInfo()
  },
  computed: {
    imgUrl() {
      return process.env.VUE_APP_IP || ''
    },
  },
  methods: {
    async getHomeInfo() {
      const res = await getHomeInfo()
      const { data } = res
      this.plantMaterialList = data.plantMaterialList
      this.baseCaseList = data.baseCaseList
      this.homeIntroduce = data.homeIntroduce
    },
    goPlantList() {
      this.$router.push('/material')
    },
    goCaseLsit() {
      this.$router.push("/base")
    }
  }
};
</script>

<style lang="scss" scoped>
.pro_intro {
  letter-spacing: 2px;
  line-height: 35px;
  min-height: 88px;
  margin: 35px 0px 30px 0px;
  font-size: 22px;
  font-family: fangsong;
  padding: 10px;
  border: 5px solid transparent;
  // background: linear-gradient(white, white) padding-box,
  //   repeating-linear-gradient(
  //       -45deg,
  //       green 0,
  //       green 12.5%,
  //       transparent 0,
  //       transparent 25%,
  //       #58a 0,
  //       #58a 37.5%,
  //       transparent 0,
  //       transparent 50%
  //     )
  //     0/5em 5em;
}
.news_list {
  padding: 0 10px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.news_wraper {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  color: #333;
  line-height: 30px;
  cursor: pointer;
  :hover {
    color: cornflowerblue;
  }
}
.news_head {
  padding: 5px 10px;
  background: #0068b7;
  display: inline-block;
  color: #fff;
  line-height: 25px;
}
.top_box {
  width: 100%;
  height: 36vw;
  margin-bottom: 20px;
  ::v-deep .el-carousel__container {
    height: 36vw;
  }
  ::v-deep .el-image {
    height: 36vw;
    width: 100%;
  }
}
.divide {
  padding: 10px;
  span {
    font-size: 13px;
    color: #ccc;
    cursor: pointer;
    &:hover {
      color: #1890ff;
    }
  }
}
.case_wraper {
  // height: 250px;
  border-radius: 5px;
  // background-color: #f1f2f3;
  .item_title {
    padding: 8px;
    width: 100%;
    height: 35px;
    line-height: 26px;
    font-size: 16px;
    font-weight: 500;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .item_desc {
    font-size: 14px;
    height: 35px;
    line-height: 16px;
    color: #666;
    padding: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
@media (min-width: 472px) {
  .list_wraper {
    padding-left: 16px;
    padding-right: 16px;
  }
}
@media (min-width: 756px) {
  .list_wraper {
    padding-left: 32px;
    padding-right: 32px;
  }
}
@media (min-width: 1008px) {
  .list_wraper {
    padding-left: 70px;
    padding-right: 70px;
  }
}
@media (max-width: 472px) {
  .top_box {
    height: 50vw;
    ::v-deep .el-carousel__container {
      height: 50vw;
    }
    ::v-deep .el-image {
      height: 50vw;
      width: 100vw;
    }
  }
}
</style>
